package com.example.studentaihouduan.Controller;


import com.example.studentaihouduan.entity.Patient;
import com.example.studentaihouduan.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/patients")
@EnableCaching
public class PatientController {

    @Autowired
    private PatientService patientService;

    // 获取所有患者信息
    @GetMapping
    public List<Patient> getAllPatients() {
        return patientService.getAllPatients();
    }

    // 根据ID获取患者信息
    @GetMapping("/{id}")
    public Patient getPatientById(@PathVariable Integer id) {
        return patientService.getPatientById(id);
    }

    // 创建新患者
    @PostMapping
    public void createPatient(@RequestBody Patient patient) {
        patientService.savePatient(patient);
    }

    // 更新患者信息
    @PutMapping("/{id}")
    public void updatePatient(@PathVariable Integer id, @RequestBody Patient patient) {
        patient.setId(id);
        patientService.updatePatient(patient);
    }

    // 删除患者信息
    @DeleteMapping("/{id}")
    public void deletePatient(@PathVariable Integer id) {
        patientService.deletePatient(id);
    }
}